/*
  Copyright 2011 fullkawa

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package jp.fullkawa.xnovel.picture;

import jp.fullkawa.xnovel.Carriable;
import jp.fullkawa.xnovel.Layerable;
import jp.fullkawa.xnovel.Locatable;

/**
 * 人物等の画像
 * フェード表示される
 * @author fullkawa
 */
public class Figure extends Picture implements Carriable, Layerable, Locatable
{
	/**
	 * 画像が配置されているレイヤ
	 */
	private String layerId;

	/**
	 * iPhoneが縦の時に表示する基準位置
	 */
	private int tatePos = 2;
	/*
	 * ※基準位置とは、PCやMacキーボードのテンキーを見て下さい。その数値の並びです。
	 * 　７８９
	 * 　４５６
	 * 　１２３
	 * 例えば「2」を指定した場合、「中央寄せ」「画面下にくっつける」表示をします。
	 */

	/**
	 * Y方向の微調整値。単位はピクセル
	 */
	private int tateAdjust = 0;

	/**
	 * iPhoneが横の時に表示する基準位置
	 */
	private int yokoPos = 8;

	/**
	 * X方向の微調整値。単位はピクセル
	 */
	private int yokoAdjust = 0;

	/**
	 * フェード時間。単位は秒
	 */
	private double fadeTime = 0.5;

	/**
	 * アルバムに追加されたときのキャプション
	 */
	private String caption;

	public Figure(){}

	public Figure(String src)
	{
		this();
		this.setSrc(src);
		this.setChange(true);
	}

	public Figure(String src, int tatePos, int yokoPos)
	{
		this(src);
		this.setTatePos(tatePos);
		this.setYokoPos(yokoPos);
	}

	public String getLayerId() {
		return layerId;
	}

	public void setLayerId(String layerId) {
		this.layerId = layerId;
	}

	public int getTatePos() {
		return tatePos;
	}

	public void setTatePos(int tatePos) {
		this.tatePos = tatePos;
	}

	public int getTateAdjust() {
		return tateAdjust;
	}

	public void setTateAdjust(int tateAdjust) {
		this.tateAdjust = tateAdjust;
	}

	public int getYokoPos() {
		return yokoPos;
	}

	public void setYokoPos(int yokoPos) {
		this.yokoPos = yokoPos;
	}

	public int getYokoAdjust() {
		return yokoAdjust;
	}

	public void setYokoAdjust(int yokoAdjust) {
		this.yokoAdjust = yokoAdjust;
	}

	public double getFadeTime() {
		return fadeTime;
	}

	public void setFadeTime(double fadeTime) {
		this.fadeTime = fadeTime;
	}

	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	@Override
	public String getTag()
	{
		if (this.isChange() == false)
		{
			return null;
		}
		StringBuilder tag = new StringBuilder();

		tag.append("<fg id=\"");
		if (this.getLayerId() != null) tag.append(this.getLayerId());
		tag.append("\" src=\"");
		if (this.getSrc() != null) tag.append(this.getSrc());
		tag.append("\" time=\"");
		tag.append(this.getFadeTime());
		tag.append("\" tate_pos=\"");
		tag.append(this.getTatePos());
		if (this.getTateAdjust() > 0)
		{
			tag.append(",");
			tag.append(this.getTateAdjust());
		}
		tag.append("\" yoko_pos=\"");
		tag.append(this.getYokoPos());
		if (this.getYokoAdjust() > 0)
		{
			tag.append(",");
			tag.append(this.getYokoAdjust());
		}
		tag.append("\" />");

		return tag.toString();
	}
}
